package com.njitzx.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.njitzx.annotation.Log;
import com.njitzx.en.BusinessType;
import com.njitzx.entity.dto.OrderPageDTO;
import com.njitzx.entity.po.Order;
import com.njitzx.entity.vo.OrderDetailVO;
import com.njitzx.entity.vo.OrderPageVO;
import com.njitzx.service.OrderService;
import com.github.pagehelper.PageInfo;
import com.njitzx.util.HttpClientUtil;
import com.njitzx.websocket.WebSocketServer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.njitzx.entity.vo.Result;
import org.apache.http.Header;
import org.apache.http.HttpHeaders;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.message.BasicHeader;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import lombok.RequiredArgsConstructor;

//import org.springframework.http.HttpHeaders;

import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author 周鑫
 * @since 2024-08-20
 */
@Api(tags = "订单表接口")
@RestController
@RequestMapping("/orders")
@RequiredArgsConstructor
public class OrderController {




    private final OrderService orderService;

    @Log(title = "查询订单号", businessType = BusinessType.OTHER)
    @ApiOperation("订单表分页查询")
    @GetMapping
    public Result findPage(OrderPageDTO orderPageDTO) {
        OrderPageVO orderPageVO = orderService.findPage(orderPageDTO);
        return Result.success(orderPageVO);
    }

    @ApiOperation("查看订单明细")
    @GetMapping("/{orderId}")
    public Result findById(@PathVariable Integer orderId) {
        List<OrderDetailVO> orderDetailVO = orderService.findById(orderId);
        return Result.success(orderDetailVO);
    }

    @ApiOperation("新增订单表")
    @PostMapping
    public Result add(@RequestBody Order order) {
        orderService.add(order);
        return Result.success();
    }

    @ApiOperation("修改订单表")
    @PutMapping("/{orderId}/{status}")
    public Result modifyStatus(@PathVariable Integer orderId, @PathVariable Integer status) {
        orderService.modifyStatus(orderId, status);
        return Result.success();
    }

    @Log(title = "删除订单号", businessType = BusinessType.DELETE)
    @ApiOperation("根据主键删除订单表")
    @DeleteMapping("/{orderId}")
    public Result removeById(@PathVariable Serializable orderId) {
        orderService.removeById(orderId);
        return Result.success();
    }

    @ApiOperation("订单发货")
    @PutMapping("/send/{orderId}/{no}")
    public Result sendOrder(@PathVariable("orderId") Integer orderId, @PathVariable("no") String no) {
        orderService.sendOrder(orderId, no);
        return Result.success();
    }

    @Log(title = "修改地址", businessType = BusinessType.UPDATE)
    @PutMapping("/address/{orderId}")
    public Result modifyAddress(@PathVariable Integer orderId, @RequestBody Map<String, String> map) {
        String address = map.get("consigneeAddr");
        orderService.modifyAddress(orderId, address);
        return Result.success();
    }

    @Log(title = "查看物流信息", businessType = BusinessType.OTHER)
    @ApiOperation("查看物流信息")
    @GetMapping("/logistics/{no}")
    public Result queryOrder(@PathVariable("no") String no) {
        JSONArray jsonArray = orderService.queryOrder(no);
        return Result.success(jsonArray);
    }

    @ApiOperation("提醒发货")
    @GetMapping("/reminder/{orderId}")
    public Result reminders(@PathVariable Integer orderId) {
        orderService.reminder(orderId);
        return Result.success();
    }

}
